//组织列表选择
import React from 'react';
import { message } from 'antd';
import PopupSelection from '../../../el/ItemComponent/PopupSelection';
import request from '@/utils/request';
interface Props {
  value?: any;
  onChange?: Function;
  paramData?: any;
  callBackFn?: Function;
  isChange?: any;
  ouHidden?: false;
}
interface State {
  popupSelection: any;
  // disablesColumn: any;
}
// 在此处组装所有的数据
class OrgPopupSelection extends React.Component<Props, State> {
  static defaultProps = {
    paramData: {}
  };
  constructor(props) {
    super(props);
    this.state = {
      popupSelection: null // 通过ref获取inputValue   popupSelection.state.inputValue
    };
  }
  componentDidMount() {
    console.log('aaaa', this.props.paramData);
  }
  onRef = (ref) => {
    this.setState({
      popupSelection: ref
    });
  };

  // 分页请求
  onRequest = async (formData) => {
    console.log('formData', formData);
    const { paramData, ouHidden } = this.props;

    let res = await request(`/yst-support/org/component/bu/paging`, {
      method: 'post',
      query: {
        ...formData,
        orders: [{ asc: false, column: 'createTime' }],
        buStatus: 'ACTIVE',
        ouId: ouHidden ? this.props?.paramData?.ouId : formData?.ouId //一般隐藏公司时，用外部传来的公司参数，否则用页面上方的条件搜索
      }
    });

    return res;
  };
  render() {
    // const { disablesColumn } = this.state;
    return (
      <>
        <PopupSelection
          overLayWidth={600}
          rowKey='id'
          modalTitle='组织列表选择'
          tableProxy={{
            request: this.onRequest,
            errCallBack: (res) => {
              message.error(res.msg || '操作失败');
            },
            props: {
              success: 'success',
              result: 'data.records',
              total: 'data.total'
            },
            autoLoad: true
          }}
          defaultSearchData={{
            // docStatus: this.props.paramData.docStatus,
            // ouId: this.props.paramData.ouId.ouId
            ...this.props.paramData
          }}
          modalTableColumns={[
            {
              title: '组织编号',
              width: 100,
              dataIndex: 'buCode'
            },
            {
              title: '组织名称',
              width: 100,
              dataIndex: 'buName'
            },
            {
              title: '所属公司',
              width: 100,
              dataIndex: 'ouName'
            },
            {
              title: '组织简称',
              width: 100,
              dataIndex: 'buAbbr'
            },
            {
              title: '组织类型',
              width: 100,
              dataIndex: 'buTypeName'
            },
            {
              title: '状态',
              width: 100,
              dataIndex: 'buStatusName'
            }
          ]}
          columns={[
            {
              title: '组织编号',
              width: 100,
              dataIndex: 'buCode'
            },
            {
              title: '组织名称',
              width: 100,
              dataIndex: 'buName'
            },
            {
              title: '所属公司',
              width: 100,
              dataIndex: 'ouName'
            },
            {
              title: '组织简称',
              width: 100,
              dataIndex: 'buAbbr'
            },
            {
              title: '组织类型',
              width: 100,
              dataIndex: 'buTypeName'
            },
            {
              title: '状态',
              width: 100,
              dataIndex: 'buStatusName'
            }
          ]}
          searchFormProps={{
            items: [
              {
                title: '组织',
                name: 'buCodeName',
                span: 8,
                formOption: {
                  type: '$input',
                  props: {
                    placeholder: '组织编码、名称、简称'
                  }
                }
              },
              {
                title: '所属公司',
                name: 'ouId',
                span: 8,
                hidden: this.props.ouHidden,
                formOption: {
                  type: '$mg-select-ou',
                  props: {
                    showColumn: 'ouName',
                    placeholder: '销售公司',
                    disabled: this.props.isChange
                  }
                }
              },
              {
                title: '组织类型',
                name: 'buType',
                span: 8,
                formOption: {
                  type: '$udc',
                  props: {
                    placeholder: '组织类型',
                    // filterValue: ['CL', 'DR', 'HD'],
                    prefixStr: '/yst-system',
                    domain: 'ORG',
                    udc: 'BU_TYPE'
                    // disabled: disablesColumn.docStatusDisable
                  }
                }
              }
            ]
          }}
          needModal={true}
          onRef={this.onRef}
          {...this.props}
        />
      </>
    );
  }
}
export default OrgPopupSelection;
